package com.liushao.controller;


import com.liushao.entity.Lend;
import com.liushao.result.Result;
import com.liushao.service.LendService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author chen
 * @since 2025-01-03
 */
@RestController
@RequestMapping("/api/core/lend")
public class LendController {

    @Autowired
    private LendService lendService;

    //http://localhost/api/core/lend/list

    @GetMapping("/list")
    public Result list(){

        List<Lend> list = lendService.selectList();

        return Result.ok().data("lendList",list);

    }

    ///api/core/lend/show/' + lendId
  @ApiOperation("获取标的的信息")
    @GetMapping("/show/{lendId}")
    public  Result show(
            @ApiParam(value = "标的id",required = true)
            @PathVariable Long lendId
    ){
      Map<String, Object> lendDetailById = lendService.getLendDetailById(lendId);

      return Result.ok().data("lendDetail",lendDetailById);

  }

  ///api/core/lend/getInterestCount/${this.invest.investAmount}/${this.lend.lendYearRate}/${this.lend.period}/${this.lend.returnMethod}`

    @ApiOperation("计算收益")
    @GetMapping("/getInterestCount/{investAmount}/{lendYearRate}/{period}/{returnMethod}")
    public Result getInterestCount(
            @ApiParam(value = "投资金额",required = true)
            @PathVariable("investAmount")BigDecimal investAmount,

            @ApiParam(value = "年化利率",required = true)
            @PathVariable("lendYearRate")BigDecimal lendYearRate,

            @ApiParam(value = "期数",required = true)
            @PathVariable("period")Integer period,

            @ApiParam(value = "还款方式",required = true)
            @PathVariable("returnMethod")Integer returnMethod
            ){
            BigDecimal money=  lendService.getInterestCount(investAmount,lendYearRate,period,returnMethod);

            return Result.ok().data("interestCount",money);

    }

}

